package com.xywy.bloodandroid.adapter;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.base.BasicAdapter;
import com.xywy.bloodandroid.bean.OrderDoctorFlag;

/**
 * *****************************************  
* @Title: DoctorOrderAdapter.java 
* @Package com.xywy.bloodandroid.adapter 
* @Description: TODO(加号的adapter) 
* @author smz
* @date 2014-12-27 下午1:19:10 
* @version V1.0   
*******************************************
 */
public class DoctorOrderAdapter extends BasicAdapter<OrderDoctorFlag> {
	private LayoutInflater inflater;
	private HashMap<Integer, String> map = null;

	public DoctorOrderAdapter(Context context, List<OrderDoctorFlag> list) {
		super(context, list);
		this.inflater = LayoutInflater.from(context);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		viewHolder holder;
		if(convertView==null){
			holder=new viewHolder();
			convertView=inflater.inflate(R.layout.item_order_doctor, null);
			holder.order_tv1=(TextView) convertView.findViewById(R.id.order_tv1);
//			holder.order_tv2=(TextView) convertView.findViewById(R.id.order_tv2);
//			holder.order_tv3=(TextView) convertView.findViewById(R.id.order_tv3);
			convertView.setTag(holder);
		}else{
			holder=(viewHolder) convertView.getTag();
		}
		holder.order_tv1.setText(list.get(position).getDate()+"\n"+"周"+list.get(position).getWeek());
		if(Integer.valueOf(list.get(position).getSurplus())>0){
		holder.order_tv2.setText("预"+changtype(list.get(position).getType()+"\n(剩余"+list.get(position).getSurplus()));
		}else if(list.get(position).getSurplus().length()>0){
			holder.order_tv2.setText("已预约完");
		}
		if(Integer.valueOf(list.get(position).getSurplus1())>0){
			
			holder.order_tv3.setText("预"+changtype(list.get(position).getType()+"\n(剩余"+list.get(position).getSurplus1()));
		}else if(list.get(position).getSurplus1().length()>0){
			holder.order_tv3.setText("已预约完");
		}
		return convertView;
	}
   private class viewHolder{
	  private  TextView order_tv1;
	  private  TextView order_tv2;
	  private  TextView order_tv3;
   }
   
   private String changtype(String type) {

		// 门诊类型 (1:普通 2：专家 3：特需 4：专科 5：会诊 6：夜间)

		if (map == null) {
			map = new HashMap<Integer, String>();
			map.put(1, "普通");
			map.put(2, "专家");
			map.put(3, "特需");
			map.put(4, "专科");
			map.put(5, "会诊");
			map.put(6, "夜间");
		}
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			Integer key = (Integer) entry.getKey();
			String value = (String) entry.getValue();
			if (Integer.valueOf(type) == key) {
				return value;
			}
		}
		return "";

	}
}
